﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;

namespace DrugStorehouseMIS.DAL
{
 public class StockInBillDAL:IStockInBillDAL
    {
        #region IStockInBill 成员

        //public IDataReader Select(string StockInNum)
        //{
        //    throw new Exception("The method or operation is not implemented.");
        //}

        public DataTable Select()
        {
            try
            {
                return SqlDbHelper.RunProcedure_DataTable(ConnectionString.ConnString, "Proc_StockInBill_Select_All");
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }


        public DataTable Select(string Status)
        {

            try
            {
                return SqlDbHelper.RunProcedure_DataTable(ConnectionString.ConnString, "Proc_StockInBill_Select_By_Status", new SqlParameter[] { new SqlParameter("@Status", Status) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public  DataTable Select(int PageIndex, int PageSize, string StockInTypeName, string StockInNum)
        {
            try
            {
                SqlParameter [] all=new SqlParameter[]
                {
                    new SqlParameter("@PageIndex",PageIndex),
                    new SqlParameter("@PageSize",PageSize),
                    new SqlParameter("@StockInTypeName",StockInTypeName),
                    new SqlParameter("@StockInNum",StockInNum)                
                };
                return SqlDbHelper.RunProcedure_DataTable(ConnectionString.ConnString, "Proc_StockInBill_Filter", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }


        public int Insert(string StockInNum, int StockInTypeNum, DateTime StockInDatetime,int SupplierNum, int DrugNum,DateTime ProductedDatetime,DateTime ExpiryDatetime,float TradePrice,float RetailPrice,float ImportPrice,string BatchNum,int Quantity, float Amount,string CreatedBy, string ApprovalBy, DateTime ApprovalDatetime, string Remark,string Status)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@StockInNum",StockInNum),
                    new SqlParameter("@StockInTypeNum",StockInTypeNum),
                    new SqlParameter("@StockInDatetime",StockInDatetime),
                    new SqlParameter("@SupplierNum",SupplierNum),
                    new SqlParameter("@DrugNum",DrugNum),
                    new SqlParameter("@ProductedDatetime",ProductedDatetime),
                    new SqlParameter("@ExpiryDatetime",ExpiryDatetime),
                    new SqlParameter("@TradePrice",TradePrice),
                    new SqlParameter("@RetailPrice",RetailPrice),
                    new SqlParameter("@ImportPrice",ImportPrice),
                    new SqlParameter("@BatchNum",BatchNum),
                    new SqlParameter("@Quantity",Quantity),
                    new SqlParameter("@TotalPrice",Amount),
                    new SqlParameter("@CreatedBy",CreatedBy),
                    new SqlParameter("@ApprovalBy",ApprovalBy),
                    new SqlParameter("@ApprovalDatetime",ApprovalDatetime),
                    new SqlParameter("@Remark",Remark),
                    new SqlParameter("@Status",Status)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockInBill_Insert", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Update(string StockInNum, string StockInTypeNum, DateTime StockInDatetime, int SupplierNum, int DrugNum, DateTime ProductedDatetime, DateTime ExpiryDatetime, float TradePrice, float RetailPrice, float ImportPrice, string BatchNum, int Quantity, float Amount, string CreatedBy, string ApprovalBy, DateTime ApprovalDatetime, string Remark, string Status)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@StockInNum",StockInNum),
                    new SqlParameter("@StockInTypeNum",StockInTypeNum),
                    new SqlParameter("@StockInDatetime",StockInDatetime),
                    new SqlParameter("@SupplierNum",SupplierNum),
                    new SqlParameter("@DrugNum",DrugNum),
                    new SqlParameter("@ProductedDatetime",ProductedDatetime),
                    new SqlParameter("@ExpiryDatetime",ExpiryDatetime),
                    new SqlParameter("@TradePrice",TradePrice),
                    new SqlParameter("@RetailPrice",RetailPrice),
                    new SqlParameter("@ImportPrice",ImportPrice),
                    new SqlParameter("@BatchNum",BatchNum),
                    new SqlParameter("@Quantity",Quantity),
                    new SqlParameter("@TotalPrice",Amount),
                    new SqlParameter("@CreatedBy",CreatedBy),
                    new SqlParameter("@ApprovalBy",ApprovalBy),
                    new SqlParameter("@ApprovalDatetime",ApprovalDatetime),
                    new SqlParameter("@Remark",Remark),
                    new SqlParameter("@Status",Status)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockInBill_Update", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Delete(string StockInNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockInBill_Delete", new SqlParameter[] { new SqlParameter("@StockInNum", StockInNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        #endregion
    }
}
